package com.heima.controller;


import com.heima.pojo.Dept;
import com.heima.repository.DeptRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@RestController
@RequestMapping("/dept")
public class DeptController {
    @Value("${server.port}")
    private String port;

    @Autowired
    private DeptRepository repository;

    @GetMapping("/findAll")
    public Collection<Dept> findAll() {
        return repository.findAll();
    }
    @GetMapping("/findById/{id}")
    public Dept findById(@PathVariable Integer id) {
        return repository.findById(id);
    }
    @PostMapping("/save")
    public void save(@RequestBody Dept dept){
        repository.save(dept);
    }
    @PutMapping("/update")
    public void update(@RequestBody Dept dept){
        repository.save(dept);
    }
    @DeleteMapping("/delete/{id}")
    public void save(@PathVariable Integer id){
        repository.deleteById(id);
    }

    @GetMapping("/index")
    public String port(){
        return "当前端口是:"+port;
    }
}
